package com.yunxitest.yunxitest.item.storage

import android.content.Context
import android.os.storage.StorageManager
import com.yunxitest.yunxitest.Interface.IDetectItem
import com.yunxitest.yunxitest.Interface.IResultCallback

/**
 * Created by apple on 2018/10/19.
 */
class USBStorageManager(val context:Context,val inResultCallback: IResultCallback) : IDetectItem {


    override fun startDetect() {
        if(isUSBStoraeExist(context)){
            inResultCallback.success()
        }else{
            inResultCallback.fail("U盘未挂载")
        }
    }
    fun isUSBStoraeExist(context: Context): Boolean{
        var hasUSBStorage=false
        val storageManager = context.getSystemService(Context.STORAGE_SERVICE) as StorageManager
        val volumes = storageManager.storageVolumes
        for (i in volumes.indices) {
            if (volumes[i].isRemovable && !volumes[i].getDescription(context).contains("内部共享存储空间")
                    && !volumes[i].getDescription(context).contains("SD")) {
                hasUSBStorage=true
            }
        }
        return hasUSBStorage
    }

    override fun finish() {

    }

}